﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Xml;
using Warensoft.Unity.Communication.Client;
using Warensoft.Unity.Communication.Client.Contracts;
using Warensoft.Unity.Communication.Client.DataClient;
using Warensoft.Unity.Communication.Client.OData;
using System.Data.SqlClient;
using System.Data;

namespace TestClient
{
    class Program
    {
        static void Main(string[] args)
        {
            //using (SqlConnection con = new SqlConnection("server=.;database=northwind;uid=sa;pwd=p@ssw0rd"))
            //{
            //    var cmd = con.CreateCommand();
            //    cmd.CommandText = "select * from customers";
            //    //cmd.Parameters.AddWithValue("@p1","alfki");
            //    //cmd.Parameters.AddWithValue("@p2", "anatr");
            //    var adpt = new SqlDataAdapter(cmd);
            //    DataSet ds = new DataSet();
            //    adpt.Fill(ds);
            //    var rows = ds.Tables[0].Rows.Cast<DataRow>().OrderBy(row => row["CompanyName"]).Select (row=>row["CompanyName"]);
            //}
            //Warensoft.Unity .Communication .Client 
            //DataContext context = new DataContext("http://localhost:45413/Default.aspx");
            Thread t = null;
            t = new Thread(() =>
            {
                while (true)
                {
                    var cm=CommunicationManager.CreateInstance();
                    cm.Update();
                    Thread.Sleep(50);
                }
            });
            t.Start();
            var httpclient = CommunicationManager.CreateInstance().GetHttpClient();
            httpclient.BeginGetHttpContent("http://localhost:17737/test11/", new Action<string>((r) => 
            {
                Console.WriteLine(r);
            }));
            //while (context.SchemaLoaded == false)
            //{

            //}
            ////for (int i = 0; i < 50; i++)
            ////{
            ////    var entity = context.Tables["tb_Students"].NewEntity();
            ////    entity["ID"] = Guid.NewGuid();
            ////    entity["StudentName"] = "sss" + i;
            ////    entity["Age"] = i;
            ////    entity["Gender"] = false;
            ////    context.Tables["tb_Students"].Add(entity);
            ////}
            ////context.SaveChanges();
           
            //Console.Read();
            //Console.WriteLine("loading");
            //DataQuery query = new DataQuery();
            //context.Tables["tb_Students"].LoadAsync(() =>
            //{
            //    var students = context.Tables["tb_Students"].Entities.Select(en => en["StudentName"].ToString());
            //    int i = 0;
            //}, query.EqualsTo("ID", new Guid("b955d62d-7c68-418e-aa18-00e904818c55")));
            
            Console.Read();
        }

       
    }
}
